#include <stdio.h>
#include <stdlib.h>
#include "Alumno.h"

#define ARCHIVO "Alumnos.txt"

Alumno alumnos[] = 
    {
    {125,"100994091","Valencia","MARCO","MORALES",6.5},
    {233,"100691842","Madrid","CRISTIAN","PEREZ",2.1},
    {12,"100194281","Cuenca","JORGE","GARCIA",6.8},
    {44,"100046076","Guadalajara","CAROLINA","SANTILLANA",6.8},
    {48,"100886999","Toledo","ANTONIO","CRUZ",0.2},
    {91,"100117342","Segovia","ÁLVARO","RIVERA",0},
    {122,"100355305","Ávila","JAIME","CABRERA",5.5},
    {212,"100922125","Soria","ADRIAN","CABRERA",8.8},
    {291,"100433370","Zaragoza","JULIAN","TORRES",8.8},
    {111,"100572200","León","MARIA","HIDALGO",2.8},
    {108,"100358889","Zamora","YOLANDA","PEREZ",6.7},
    {93,"100538832","Salamanca","SERGIO","CANO",6.4},
    {25,"100594287","Pontevedra","JULIAN","SANTILLANA",4.2},
    {88,"100085956","Burgos","MARTA","RAMOS",6.6},
    {0, "","","","",0}
    };

void Escribir(const char* archivo, Alumno *p_alumno);

int main (int ac, char **av)
    {
    printf ("sizeof(Alumno) =%ld\n",sizeof(Alumno));
    printf ("sizeof(Alumnos)=%ld\n",sizeof(alumnos));

    Escribir(ARCHIVO, alumnos);
    }

void Escribir(const char* archivo, Alumno *p_alumno)
    {
    FILE *stream = fopen(ARCHIVO,"w");
    if (!stream) {perror(NULL); exit(666);}

    for (Alumno *p = p_alumno; p->id>0; p++) 
        Alumno_escribir(stream,p);
     
    fclose(stream);
    }
